package com.heima.controller;

import com.heima.result.Result;
import com.heima.service.HomePageService;
import com.heima.vo.*;
import io.swagger.annotations.Api;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@RestController
@Api(tags = "首页数据")
@Slf4j
public class HomePageController {
    @Autowired
    private HomePageService homePageService;
    /**
     * 首页获取基础数据
     */
    @GetMapping("/index")
    public Result<BaseInfoVo> getBaseInfo(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate beginCreateTime,
                                          @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate endCreateTime){
        log.info("首页获取基础数据");
        BaseInfoVo baseInfoVo=homePageService.getBaseInfo(beginCreateTime,endCreateTime);
        return Result.success(baseInfoVo);
    }
    /**
     * 首页获取今日数据
     */
    /*@GetMapping("/index/getTodayInfo")
    public Result<TodayInfo> getTodayInfo(LocalDate now){
        log.info("首页获取今日数据");
        TodayInfo todayInfo=homePageService.getTodayInfo(now);
        return Result.success(todayInfo);
    }*/
    /**
     * 首页获取待跟进数据
     */
    /*@GetMapping("/index/getTodoInfo")
public Result<TodoInfo> getTodoInfo(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate beginCreateTime,
                                    @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate endCreateTime){
        log.info("首页获取待跟进数据");
        TodoInfo todoInfo=homePageService.getTodoInfo(beginCreateTime,endCreateTime);
        return Result.success(todoInfo);
    }*/
    /**
     * 首页获取商机转化排行榜
     */
    @GetMapping("/index/businessChangeStatistics")
    public Result<List<BusinessChangeVo>> businessChangeStatistics(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate beginCreateTime,
                                                                   @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate endCreateTime){
        log.info("首页获取商机转化排行榜");
        List<BusinessChangeVo> list=homePageService.businessChangeStatistics(beginCreateTime,endCreateTime);
        return Result.success(list);
    }
    /**
     * 首页获取线索转化排行榜
     */
    @GetMapping("/index/salesStatistic")
    public Result<List<SalesStatisticVo>> salesStatistic(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate beginCreateTime,
                                                          @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate endCreateTime){
        log.info("首页获取线索转化排行榜");
        List<SalesStatisticVo> list=homePageService.salesStatistic(beginCreateTime,endCreateTime);
        return Result.success(list);
    }
    /**
     * 线索转化漏斗统计
     */
    @GetMapping("/report/getVulnerabilityMap/{begin}/{end}")
    public Result<ReportVo> getVuInerabilityMap(@PathVariable String begin,
                                                @PathVariable String end){
        log.info("线索转化漏斗统计");
        ReportVo reportVo=homePageService.getVuInerabilityMap(begin,end);
        return Result.success(reportVo);
    }

}
